import threading
import time
# 多线程安全问题
ticket = 100


def sale_ticket():
    global ticket
    for i in range(1000):
        if ticket > 0:
            print(threading.current_thread().name + '>>正在出售第{}张票'.format(ticket))
            ticket -= 1
        time.sleep(1)


def start():
    for i in range(2):
        t = threading.Thread(target=sale_ticket)
        t.start()


if __name__ == '__main__':
    start()
